package com.mygdx.canyonbunny.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.mygdx.canyonbunny.object.Horse;
import com.mygdx.canyonbunny.util.AssetLoader;

public class GameRenderer {

	private GameWorld myWorld;
	private OrthographicCamera cam;
	private ShapeRenderer shapeRenderer;

	private SpriteBatch batcher;

	private GameWorld gameWorld;

	private Horse horse;
	private Animation horseAnimation;
	private TextureRegion a;

	private int midPointY;
	private int gameHeight;

	public GameRenderer(GameWorld gameWorld, int gameHeight, int midPointY) {
		this.gameWorld = gameWorld;
		this.gameHeight = gameHeight;
		this.midPointY = midPointY;

		cam = new OrthographicCamera();
		cam.setToOrtho(true, 136, gameHeight);

		batcher = new SpriteBatch();
		batcher.setProjectionMatrix(cam.combined);
		shapeRenderer = new ShapeRenderer();
		shapeRenderer.setProjectionMatrix(cam.combined);
		// horse = new Horse(33, 50, 39, 24);
		horse = gameWorld.getHorse();
		horseAnimation = AssetLoader.horseAnimation;
		a = AssetLoader.horse1;

	}

	public void render(float runTime) {

		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		shapeRenderer.begin(ShapeType.Filled);

		// Draw Background color
		shapeRenderer.setColor(55 / 255.0f, 80 / 255.0f, 100 / 255.0f, 1);
		shapeRenderer.rect(0, 0, 136, midPointY + 66);

		// Draw Grass
		shapeRenderer.setColor(111 / 255.0f, 186 / 255.0f, 45 / 255.0f, 1);
		shapeRenderer.rect(0, midPointY + 66, 136, 11);

		// Draw Dirt
		shapeRenderer.setColor(147 / 255.0f, 80 / 255.0f, 27 / 255.0f, 1);
		shapeRenderer.rect(0, midPointY + 77, 136, 52);

		shapeRenderer.end();
		

		batcher.begin();

		 batcher.enableBlending();
		  batcher.draw(horseAnimation.getKeyFrame(runTime), horse.getX(),
		  horse.getY(), horse.getWidth() / 2.0f,
		  horse.getHeight() / 2.0f, horse.getWidth(), horse.getHeight(),
		  1, 1, 0);
		 batcher.end();
	}
}
